// 将下面代码使用promsie的方式改进

setTimeout(function() {
    var a = 'hello '
    setTimeout(function() {
        var b = 'girl '
        setTimeout(function() {
            var c = 'I love you'
            console.log('setTimeout');
            
            console.log(a + b + c)
        }, 100)
    }, 100)
},100)

// 改造
new Promise(resolve => {
    var a = 'hello '
    setTimeout(() => resolve(a), 100)
}).then(val => {  
    var b = 'girl ' 
    return new Promise(resolve => {
        setTimeout(() => resolve(val + b), 100)
    })
}).then(val => {
    var c = 'I love you'
    setTimeout(() => {
        console.log('promise');
        console.log(val + c)
    }, 100);     
})

//改造2
function fn1(a) {
    return new Promise(resolve => {
        setTimeout(() => resolve(a), 100)
    })
}

function fn2(b) {
    return new Promise(resolve => {
        setTimeout(() => resolve(b), 100)
    })
}
function fn3(c) {
    return new Promise(resolve => {
        setTimeout(() => resolve(c), 100)
    })
}

Promise.all([fn1('hello '), fn2('girl '),  fn3('I love you ')]).then(res => {
    console.log('promise all');
    console.log(res.join(''))
})